package uumoi

class Country {
	String defaultName
	String iso2Code
	String iso3Code

	static hasMany = [localNames: LocalisedText]

	static constraints = {
	}

	static mapping = {
		localNames fetch: 'join'
		localNames cascade: 'all'
	}

	public String getFlagPath() {
		return "images/flags/" + defaultName + ".png"
	}

	public String getLocalName(Locale locale) {
		if (!locale)
			return defaultName

		for (LocalisedText lt : localNames) {
			if (locale.getLanguage().equals(iso2Code))
				return lt.text
		}

		return defaultName
	}
}
